/**
 * author:Administrator
 * date:2016/3/16
 * desc:TODO
 */
"use strict";

let RawQuery = require('./_RawQuery.js');
class ShopQuery extends RawQuery {
  constructor() {
    super();
  }

  * findByVendor(vendorId, pageIndex, pageSize) {
    let sql = "select shop.* " +
      " from shop " +
      " where shop.vendorId='%vendorId' " +
      " limit %start,%end";

    let offset = this.offset(pageIndex, pageSize);
    sql = sql.replace('%vendorId', vendorId)
      .replace('%start', offset.start)
      .replace('%end', offset.end);
    return yield this.query(sql);
  }

  /******************************************************
   *                vendor 查询 shop 详情                *
   ******************************************************/
  * vendorShopDetail(vendorId, shopId) {
    // shop
    // 相关的ware
    // location
    let sql = "select shop.*, " +
      " ware.name as wareName, ware.id as wareId, " +
      " location.name as locName, " +
      " category.name as cateName " +
      " from `ware`,`shop`,`category`,`location`, `shopware` " +
      " where shop.id='%shopId' " +
      " and shop.vendorId='%vendorId' " +
      " and shop.locationId = location.id " +
      " and shopware.wareId = ware.id " +
      " and shopware.shopId = shop.id " +
      " and category.id = ware.categoryId";
    sql = sql.replace('%vendorId', vendorId)
      .replace('%shopId', shopId);
    return yield this.query(sql);
  }

}

module.exports = new ShopQuery();